/**************************************************************************(C)*
 *
 *  This file is part of the GreenHills project
 *  Copyright (C) 2009  Tieto Corporation
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  Not for commmercial use. Only with Tieto permission.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 *************************************************************************(C)*/

#pragma once

#include "iroomitem.h"

#include <string>
#include <vector>
#include "coredll.h"

namespace greenhills {
namespace core {

#define DEFAULT_ROOM_ID     0x01020304
#define DEFAULT_ROOM_NAME   "Defualt room"
#define DEFAULT_PASSWORD    "greenhills"

typedef int CRoomId;
typedef int CRoomType;

class IRoomListener;

/** @brief Interface decaration for room object
 *
 * Provides methods ensuring basic functionality like add, remove or modify room
 * item, and access to room items.
 */
class GH_CORE_CLASS IRoom
{
public:
    virtual ~IRoom() {}

public:
    virtual std::string name() const = 0;
    virtual core::CRoomId id() const = 0;

public: //room item handling
    virtual bool isEmpty() const = 0;
    virtual core::IRoomItem *item(const core::CItemId &pItemId) const = 0;
    virtual core::IRoomItem *itemAt(int index) const = 0;
    virtual int indexOf(const core::CItemId &pItemId) const = 0;
    virtual int count() const = 0;

    virtual IRoomItem * createItem(const core::CItemId &pItemId,
                                   const std::string &pItemName,
                                   const core::CItemType &pItemType) = 0;

    virtual bool addItem(const core::CItemId &pItemId,
                         const std::string &pItemName,
                         const core::CItemType &pItemType) = 0;
    virtual bool updateItem(const core::CItemId &pItemId,
                            const unsigned char *pData,
                            unsigned int pLength) = 0;
    virtual bool removeItem(const core::CItemId &pItemId) = 0;

public: //listeners management
    virtual void registerListener(core::IRoomListener *listener) = 0;
    virtual void unregisterListener(core::IRoomListener *listener) = 0;
    virtual void unregisterAllListeners() = 0;
};

/** @brief Interface decaration for room listeners
 *
 * This interface is used for sending notifications to all objects interested in
 * certain room object.
 */
class GH_CORE_CLASS IRoomListener
{
public:
    virtual void aboutToAddItem(core::IRoom *pRoom,
                           const core::CItemId &pItemId) = 0;
    virtual void aboutToUpdateItem(core::IRoom *pRoom,
                             const core::CItemId &pItemId) = 0;
    virtual void aboutToRemoveItem(core::IRoom *pRoom,
                             const core::CItemId &pItemId) = 0;

    virtual void itemAdded(core::IRoom *pRoom,
                           const core::CItemId &pItemId,
                           const std::string &pItemName,
                           const core::CItemType &pItemType) = 0;
    virtual void itemUpdated(core::IRoom *pRoom,
                             const core::CItemId &pItemId,
                             const unsigned char *pData,
                             unsigned int pLength) = 0;
    virtual void itemRemoved(core::IRoom *pRoom,
                             const core::CItemId &pItemId) = 0;
};

} //namespace core
} //namespace greenhills
